package com.cy.web.common.interceptor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalTime;

public class TimeAccessInterceptor implements HandlerInterceptor {

    public static final Logger log = LoggerFactory.getLogger(TimeAccessInterceptor.class);

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        LocalTime now = LocalTime.now();
        int hour = now.getHour();
        log.info("time is {}",hour);
        if(hour<=6||hour>=22){
            throw new RuntimeException("请在6~22点进行操作");
        }
        return true;
    }
}
